/**
 * 标准盐酸
 */
Hcl = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_HCL_BOTTLE);
	},
	init:function(){		
		this.body = new Button(this, 10, TAG_HCL, "#HCl/HCl_bottle_1.png", this.callback);
		
		var lid = new Button(this, 5, TAG_HCL_LID, "#lid.png", this.callback);
		lid.setPosition(0,40);
		lid.setScale(0.6);

		var hand = new Button(this, 9, TAG_RIGHT, "#hand_right.png", this.callback);
		hand.setPosition(cc.p(22,-31));
		hand.setScale(0.7);
		hand.setVisible(false);
		var part = new Button(this, 11, TAG_RIGHT_PART, "#hand_right_part.png", this.callback);
		part.setPosition(cc.p(22,-31));
		part.setScale(0.7);
		part.setVisible(false);
		
		this.body.setCascadeOpacityEnabled(true);
			
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	//打开瓶盖
	openLid:function(){
		var lid=this.getChildByTag(TAG_HCL_LID);
		var ber = cc.bezierBy(1,[cc.p(50,70),cc.p(60,-70),cc.p(60,-75)]);
		var rot=cc.rotateTo(1, 180);
		var spw=cc.spawn(ber,rot);
		var seq = cc.sequence(spw,this.func);
		lid.runAction(seq);
	},
	bottle_turn:function(p){
		var animFrames = [];
		for (var i = 2; i < 6; i++) {
			var str = "HCl/HCl_bottle_" + i + ".png";
			var frame = cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation = new cc.Animation(animFrames, 0.15,1);
		var action = cc.animate(animation);
		var seq=cc.sequence(action,cc.callFunc(function() {
		}, this));
		p.runAction(seq);
	},
	callback:function(p){
		var func = cc.callFunc(this.actionDone, this);
		var ddg=this.getParent().getChildByTag(TAG_DDG_DDG);
		var action=gg.flow.flow.action;
		var hand=this.getChildByTag(TAG_RIGHT);
		var part=this.getChildByTag(TAG_RIGHT_PART);
		switch(p.getTag()){
		case TAG_HCL_LID:
			this.openLid();
			break;
		case TAG_HCL:
			if(action==ACTION_DO1){
				hand.setVisible(true);				
				part.setVisible(true);
				var mov1=cc.moveTo(0.1, cc.p(1152,394));
				var mov2=cc.moveTo(0.1, cc.p(1132,384));
				var mov3=cc.moveTo(0.1, cc.p(1152,364));
				var mov4=cc.moveTo(0.1, cc.p(1162,384));
				var mov5=cc.moveTo(0.1, cc.p(1152,384));
				var sequence=cc.sequence(mov1,mov2,mov3,mov4);
				var seq=cc.sequence(cc.repeat(sequence, 3),mov5,cc.callFunc(function() {
					hand.setVisible(false);				
					part.setVisible(false);		
				}, this),this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO2){			
				this.bottle_turn(p);
				var move = cc.moveTo(0.6,cc.p(774,366));
				var rot = cc.rotateTo(0.6, 310);
				var rot1=cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(1152,384));
				var seq = cc.sequence(cc.delayTime(0.6),cc.callFunc(function() {
					var lid=this.getChildByTag(TAG_HCL_LID);
					lid.setVisible(false);
					hand.setVisible(true);				
					part.setVisible(true);
				}, this),move,rot,cc.callFunc(function(){
					this.getParent().water.flowRight(p,65,cc.p(10,84),1);
					ddg.lineUp(cc.p(1,70));
				}, this),cc.delayTime(2),rot1,move1,cc.callFunc(function() {
					hand.setVisible(false);				
					part.setVisible(false);
					p.setSpriteFrame("HCl/HCl_bottle_1.png");
				}, this),this.callNext);
				this.runAction(seq);
				
				var seq2=cc.sequence(cc.delayTime(0.5),cc.rotateTo(0.6,30),cc.delayTime(3),cc.rotateTo(0.6, 0));
				ddg.runAction(seq2)
			}else if(action==ACTION_DO3){
				this.bottle_turn(p);
				var move = cc.moveTo(0.6,cc.p(774,366));
				var mov1=cc.moveTo(0.6, cc.p(1152,384));
				var rot = cc.rotateTo(0.6, 310);
				var rot1=cc.rotateTo(0.6, 0);
				var seq = cc.sequence(cc.delayTime(0.6),cc.callFunc(function() {
					hand.setVisible(true);				
					part.setVisible(true);
				}, this),move,rot,cc.callFunc(function(){
					this.getParent().water.flowRight(p,65,cc.p(10,84),1);
					ddg.lineUp(cc.p(1,340));
				}, this),cc.delayTime(2.5),rot1,mov1,cc.callFunc(function() {
					this.removeFromParent();
				}, this));
				this.runAction(seq);
				
				var seq2=cc.sequence(cc.delayTime(0.5),cc.rotateTo(0.6,30),cc.delayTime(2.4),cc.callFunc(function() {
					var pic=new cc.Sprite("#0_0_0.png");
					pic.setPosition(cc.p(89,138));
					pic.setScale(1.3);
					ddg.addChild(pic);

					var line=new cc.Sprite("#beaker_line.png");
					line.setPosition(cc.p(50,21));
					line.setRotation(-30);
					pic.addChild(line);
					line.runAction(cc.sequence(cc.moveTo(0.3, cc.p(50,72)),cc.delayTime(0.6),cc.rotateTo(0.6, 0)));

					pic.runAction(cc.sequence(cc.delayTime(2),cc.callFunc(function() {
						pic.removeFromParent()
					}, this)));
				}, this),cc.delayTime(1),cc.rotateTo(0.6, 0),cc.delayTime(0.5),this.callNext);
				ddg.runAction(seq2)
			}
			break;
		}
	},
	actionDone:function(p){
		var func = cc.callFunc(this.actionDone, this);
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_HCL_LID:
			gg.flow.next();
			break;
		case TAG_HCL:
			gg.flow.next();
			break;
		}
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});